home *** CD-ROM | disk | FTP | other *** search
-
- #if 0
- #define WeBeHere(StringPtr) DebugStr(StringPtr)
- #else
- #define WeBeHere(StringPtr)
- #endif
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- #ifndef __DEBUGTOOLS__
- #include "DebugTools.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (ie. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // --- ListPart Includes ---
-
- #ifndef _LISTPART_
- #include "ListPart.h"
- #endif
-
- #ifndef _LISTPARTGLOBALS_
- #include "ListPartGlobals.h"
- #endif
-
- #ifndef _LISTPARTUTILS_
- #include "ListPartUtils.h"
- #endif
-
- #ifndef _LISTPARTDEF_
- #include "ListPartDef.h"
- #endif
-
- // --- OpenDoc Includes ---
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef SOM_ODValueNameSpace_xh
- #include <ValueNS.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _BNDNSUTL_
- #include <BndNSUtl.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _TEMPITER_
- #include <TempIter.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- // --- Macintosh Includes ---
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __GXMATH__
- #include <GXMath.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- /*
- #ifndef _ALTPOINT_
- #include <AltPoint.h>
- #endif
-
- #ifndef __DEBUGTOOLS__
- #include "DebugTools.h"
- #endif
-
- #ifndef _LISTPART_
- #include "CPListPart.h"
- #endif
-
- #ifndef _PARTUTILS_
- #include "PartUtils.h"
- #endif
-
- #ifndef _LISTPARTDEF_
- #include "ListPartDef.h"
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODPstObj_
- #include <PstObj.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStdProps_xh
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStdTypes_xh
- #include <StdTypes.xh>
- #endif
-
- #ifndef _STDDEFS_
- #include <StdDefs.xh>
- #endif
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef SOM_ODCmdDefs_xh
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODStorageU_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTrnsform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWinStat_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
- */
-
- //====================================================================
- // Miscellaneous
- //====================================================================
-
-
- #ifdef applec
- #pragma segment ListPartList
- #endif
-
- pascal void ControlThumbAction(void);
- pascal void ControlThumbAction(void)
- {
- ((ListPart *)gMySelf)->TheControlThumbAction(gEv, gFacet, gControl);
- }
-
- pascal void ControlAction(ControlHandle theControl, short thePart);
- pascal void ControlAction(ControlHandle theControl, short thePart)
- {
- ((ListPart *)gMySelf)->TheControlAction(gEv, gFacet, theControl, thePart);
- }
-
- void UtilSetControlValue(ControlHandle theControl, short theValue);
- void UtilSetControlValue(ControlHandle theControl, short theValue)
- {
- GrafPtr curPort;
- ::GetPort(&curPort);
- Rect r = curPort->portRect;
- short dh = -r.left;
- short dv = -r.top;
- ::SetOrigin(0, 0);
- ::OffsetRgn(curPort->clipRgn, dh, dv);
- ::SetControlValue(theControl, theValue);
- ::OffsetRgn(curPort->clipRgn, -dh, -dv);
- ::SetOrigin(-dh, -dv);
- }
-
- void ListPart::TheControlAction(Environment* ev, ODFacet* theFacet, ControlHandle theControl, short thePart)
- {
- short oldVal = ::GetControlValue(theControl);
- short theMin = ::GetControlMinimum(theControl);
- short theMax = ::GetControlMaximum(theControl);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)theFacet->GetPartInfo(ev);
- short locNbVis = lfip->fNbVis;
- short newVal = oldVal;
- switch (thePart)
- {
- case kControlUpButtonPart: if (oldVal > theMin) newVal = oldVal-1; break;
- case kControlDownButtonPart: if (oldVal < theMax) newVal = oldVal+1; break;
- case kControlPageUpPart: if (oldVal > theMin) newVal = oldVal-locNbVis+1; break;
- case kControlPageDownPart: if (oldVal < theMax) newVal = oldVal+locNbVis-1; break;
- }
- ::SetControlValue(theControl, newVal);
- newVal = ::GetControlValue(theControl);
- if (oldVal != newVal) ScrollTo(ev, theFacet, newVal);
- }
-
- void ListPart::TheControlThumbAction(Environment* ev, ODFacet* theFacet, ControlHandle theControl)
- {
- Point localPt;
- long mytmin, myval, ctlmin, ctlmax, rtop, rleft, rbottom, rright;
- Boolean insideArea;
-
- rtop = (*theControl)->contrlRect.top;
- rleft = (*theControl)->contrlRect.left;
- rbottom = (*theControl)->contrlRect.bottom;
- rright = (*theControl)->contrlRect.right;
- ::GetMouse(&localPt);
- mytmin = localPt.v - gInitDelta;
- ctlmin = (*theControl)->contrlMin;
- ctlmax = (*theControl)->contrlMax;
- myval = (((mytmin-rtop-16)*(ctlmax-ctlmin)*100) / (rbottom-48-rtop))+50;
- myval = ctlmin + (myval / 100);
- if (myval < ctlmin) myval = ctlmin;
- if (myval > ctlmax) myval = ctlmax;
- insideArea = ((localPt.h <= rright + 23) && (localPt.h >= rleft - 24));
- if (insideArea && (gTempoVal != myval))
- {
- PenState thePnState;
- ::GetPenState(&thePnState);
- PenNormal();
- gTempoVal = myval;
- mytmin = (*theControl)->contrlValue;
- (*theControl)->contrlValue = myval;
- ScrollTo(ev, theFacet, myval);
- (*theControl)->contrlValue = mytmin;
- ::SetPenState(&thePnState);
- }
- }
-
- void ListPart::HandleMouseDownInList(Environment* ev, ODEventData* event, ODFacet* facet, Point macPoint)
- {
- WeBeHere("\pListPart::HandleMouseDownInList");
- CFocus foc(ev, facet);
-
- short ctlPart, oldValue, newValue, scrollThumbOk = 0;
- ControlActionUPP myRoutine;
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- ControlHandle aCtl = lfip->fListCtl;
-
- if (aCtl)
- {
- gMySelf = (ODPart *)this;
- gControl = aCtl;
- gEv = ev;
- gFacet = facet;
- oldValue = ::GetControlValue(aCtl);
-
- GrafPtr curPort;
- ::GetPort(&curPort);
- Rect r = curPort->portRect;
- short dh = -r.left;
- short dv = -r.top;
- SetOrigin(0, 0);
- OffsetRgn(curPort->clipRgn, dh, dv);
- macPoint.h += dh;
- macPoint.v += dv;
-
- if ((ctlPart = ::TestControl(aCtl, macPoint)) != 0)
- {
- if (fKind == kActive) if (fLineOpened) CloseCellOpened(ev);
- switch (ctlPart)
- {
- case kControlIndicatorPart :
- if (fAutoThumb)
- {
- gTempoVal = ::GetControlValue(aCtl);
- gInitDelta = macPoint.v - (*((RgnHandle)((*aCtl)->contrlData)))->rgnBBox.top;
- myRoutine = (ControlActionUPP)NewRoutineDescriptor((ProcPtr)ControlThumbAction, kPascalStackBased, kPowerPCISA);
- if (::TrackControl(aCtl, macPoint, myRoutine) == kControlIndicatorPart) scrollThumbOk = 1;
- if (gTempoVal != ::GetControlValue(aCtl)) scrollThumbOk = 0;
- DisposeRoutineDescriptor(myRoutine);
- }
- else if (::TrackControl(aCtl, macPoint, (ControlActionUPP)-1L) != kControlIndicatorPart) scrollThumbOk = 1;
- if (scrollThumbOk == 0) ScrollTo(ev, facet, ::GetControlValue(aCtl));
- break;
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- case kControlPageUpPart:
- case kControlPageDownPart:
- myRoutine = NewControlActionProc(ControlAction);
- do ::TrackControl(aCtl, macPoint, myRoutine); while (::StillDown());
- DisposeRoutineDescriptor(myRoutine);
- break;
- }
- }
-
- OffsetRgn(curPort->clipRgn, -dh, -dv);
- SetOrigin(-dh, -dv);
- macPoint.h -= dh;
- macPoint.v -= dv;
-
- Rect bounds = lfip->fUsedRect;
- bounds.right -= 18;
- bounds.top += 3;
- bounds.left += 3;
- bounds.bottom -= 3;
- short where;
- char val;
- gTempoVal = 0;
- if (::PtInRect(macPoint, &bounds))
- if (FirstClick(ev, facet, event, &where, &val, macPoint))
- while (::StillDown()) StillClick(ev, facet, where, val);
-
- if ((oldValue != (newValue = ::GetControlValue(aCtl))) || (gTempoVal != 0))
- {
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- ODFrameFacetIterator* facets = proxy->GetFrame(ev)->CreateFacetIterator(ev);
- for (ODFacet* fct = facets->First(ev);
- facets->IsNotComplete(ev);
- fct = facets->Next(ev) )
- {
- if (fct != facet)
- {
- CFocus lfoc(ev, fct);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)fct->GetPartInfo(ev);
- UtilSetControlValue(lfip->fListCtl, newValue);
- ScrollTo(ev, fct, newValue);
- }
- }
- delete facets;
- }
- }
- }
- }
-
- void ListPart::MyAdjustCtlFacet(Environment* ev, ODFacet* facet)
- {
- WeBeHere("\pListPart::MyAdjustCtlFacet");
-
- CFocus qdPort(ev, facet);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- Rect aRect = lfip->fUsedRect;
- short locNbVis = (aRect.bottom-aRect.top-kMargin) / fLineHeight;
- if (facet->GetFrame(ev)->IsRoot(ev))
- {
- aRect.top -= 1;
- aRect.right += 1;
- aRect.bottom -= 14;
- }
- aRect.left = aRect.right - 16;
-
- WindowPtr theWind = facet->GetWindow(ev)->GetPlatformWindow(ev);
- short dh = -theWind->portRect.left;
- short dv = -theWind->portRect.top;
- SetOrigin(0, 0);
- OffsetRect(&aRect, dh, dv);
-
- ControlHandle aCtl = lfip->fListCtl;
- if (!aCtl)
- {
- short theMax = fNbLines-locNbVis+1;
- if (theMax < 1) theMax = 1;
- aCtl = NewControl(facet->GetWindow(ev)->GetPlatformWindow(ev),&aRect,"\p",0,fListIndex,1,theMax,scrollBarProc,0L);
- lfip->fListCtl = aCtl;
- }
- else
- {
- HideControl(aCtl);
- MoveControl(aCtl, aRect.left, aRect.top);
- SizeControl(aCtl, 16, aRect.bottom-aRect.top);
- short theMax = fNbLines-locNbVis+1;
- if (theMax < 1) theMax = 1;
- SetControlMaximum(aCtl, theMax);
- }
- lfip->fNbVis = locNbVis;
- }
-
- void ListPart::MyAdjustGWFacet(Environment* ev, ODFacet* facet)
- {
- WeBeHere("\pListPart::MyAdjustGWFacet");
-
- CGrafPtr port;
- GDHandle gdh;
- GWorldPtr newGWorld;
- PixMapHandle pm, npm;
- Rect bounds;
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- short locNbVis = lfip->fNbVis;
- if (locNbVis > fNbLines) locNbVis = fNbLines;
- ::SetRect(&bounds, 0, 0, fLineWidth, locNbVis * fLineHeight);
-
- CFocus qdPort(ev, facet);
- if (!fGWorld)
- {
- ::GetGWorld(&port, &gdh);
- OSErr err = ::NewGWorld(&newGWorld, fLineDepth, &bounds, nil, nil, useTempMem);
- if (err != noErr)
- {
- /*
- DebugStr("\pNewGWorld allocation failed in ListPart::MyAdjustGWFacet");
- ds("apres NewGWorld");dc();
- ds("bounds.left = ");dn(bounds.left);dc();
- ds("top = ");dn(bounds.top);dc();
- ds("right = ");dn(bounds.right);dc();
- ds("bottom = ");dn(bounds.bottom);dpg();
- ds("fLineWidth = ");dn(fLineWidth);dc();
- ds("locNbVis = ");dn(locNbVis);dc();
- ds("fLineHeight = ");dn(fLineHeight);dc();
- ds("fLineDepth = ");dn(fLineDepth);dp();
- */
- return;
- }
- ::SetGWorld(newGWorld, 0L);
- npm = ::GetGWorldPixMap(newGWorld);
- ::LockPixels(npm);
- ::EraseRect(&bounds);
- ::SetGWorld(port, gdh);
- fGWorld = newGWorld;
- fGWNbLines = locNbVis;
- fsomSelf->SetUpGraphics(ev, fGWorld);
- DrawMultCell(ev, facet, fListIndex, fListIndex+fGWNbLines-1);
- }
- else
- {
- if (locNbVis > fGWNbLines)
- {
- ::GetGWorld(&port, &gdh);
- OSErr err = ::NewGWorld(&newGWorld, fLineDepth, &bounds, nil, nil, useTempMem);
- if (err != noErr)
- {
- DebugStr("\pNewGWorld reallocation failed in ListPart::MyAdjustGWFacet");
- return;
- }
- ::SetGWorld(newGWorld, 0L);
- pm = ::GetGWorldPixMap(fGWorld);
- npm = ::GetGWorldPixMap(newGWorld);
- ::LockPixels(npm);
- ::EraseRect(&bounds);
- ::CopyBits((BitMapPtr)(*pm), (BitMapPtr)(*npm), &fGWorld->portRect, &fGWorld->portRect, srcCopy, 0L);
- ::SetGWorld(port, gdh);
- port = (CGrafPtr)fGWorld;
- fGWorld = newGWorld;
- fsomSelf->SetUpGraphics(ev, fGWorld);
- ::DisposeGWorld((GWorldPtr)port);
-
- if (fListIndex+locNbVis-1 > fNbLines)
- {
- fListIndex = fNbLines-locNbVis+1;
- UtilSetControlValue(lfip->fListCtl, fListIndex);
- DrawMultCell(ev, facet, fListIndex, fListIndex+locNbVis-1);
- }
- else DrawMultCell(ev, facet, fListIndex+fGWNbLines, fListIndex+locNbVis-1);
- fGWNbLines = locNbVis;
- }
- }
- }
-
- void ListPart::MyAdjustRectFacet(Environment* ev, Rect* theRect)
- {
- WeBeHere("\pListPart::MyAdjustRectFacet");
- short temp = (theRect->bottom-theRect->top-kMargin) / fLineHeight;
- theRect->bottom = theRect->top + temp * fLineHeight + kMargin;
- }
-
- void ListPart::AdjustFacets(Environment* ev, ODFrame* frame)
- {
- WeBeHere("\pListPart::AdjustFacets");
- // Given a frame, iterate through all of the facets and adjust them
- // according to the new frame.
-
- ODShape* usedShape = this->CalcNewUsedShape(ev, frame);
- frame->ChangeUsedShape(ev, usedShape, kODNULL);
- if (usedShape) usedShape->Release(ev);
-
- ODShape* frameShape = frame->AcquireFrameShape(ev, kODNULL);
- ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
- for (ODFacet* facet = facets->First(ev);
- facets->IsNotComplete(ev);
- facet = facets->Next(ev) )
- {
- facet->ChangeActiveShape(ev, frameShape, kODNULL);
-
- CFocus foc(ev, facet);
- ODShape* usedShape = frame->AcquireUsedShape(ev, kODNULL);
- RgnHandle rgn = usedShape->GetQDRegion(ev);
- Rect rct = (*rgn)->rgnBBox;
- usedShape->Release(ev);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- lfip->fUsedRect = rct;
- MyAdjustCtlFacet(ev, facet);
- MyAdjustGWFacet(ev, facet);
- }
- delete facets;
- frameShape->Release(ev);
- }
-
- void ListPart::DrawMultCell(Environment* ev, ODFacet* facet, short firstLine, short lastLine)
- {
- for (short i=firstLine; i<=lastLine; i++) DrawCell(ev, facet, i);
- }
-
- void ListPart::DrawCell(Environment* ev, ODFacet* facet, short theLine)
- {
- Rect cbounds;
- short hil;
- CGrafPtr port;
- GDHandle gdh;
-
- if (!fGWorld) return;
-
- ::GetGWorld(&port, &gdh);
- ::SetGWorld(fGWorld, 0);
- cbounds = fGWorld->portRect;
- cbounds.top += fLineHeight * (theLine - fListIndex);
- cbounds.bottom = cbounds.top + fLineHeight;
-
- if ((theLine < 1) || (theLine > fNbLines)) ::EraseRect(&cbounds);
- else
- {
- hil = false;
- if (((fKind == kActive) || (fKind == kPassive)) && (fSel == theLine)) hil = true;
- if ((fKind == kMultiple) && (fMul[theLine-1])) hil = true;
- if (hil) fsomSelf->FillHilCell(ev, theLine, &cbounds); else fsomSelf->FillCell(ev, theLine, &cbounds);
- }
- ::SetGWorld(port, gdh);
- }
-
- void ListPart::CopyFromGWorld(Environment* ev, ODFacet* facet)
- {
- WeBeHere("\pListPart::CopyFromGWorld");
-
- if (!fGWorld) return;
-
- CFocus foc(ev, facet);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- Rect cbounds, fbounds, rct = lfip->fUsedRect;
-
- short curCtlValue = ::GetControlValue(lfip->fListCtl);
- short locNbVis = lfip->fNbVis;
- if (locNbVis > fNbLines) locNbVis = fNbLines;
- cbounds.top = fLineHeight * (curCtlValue - fListIndex);
- cbounds.left = 0;
- fbounds.left = fbounds.top = 3;
- cbounds.bottom = cbounds.top + fLineHeight * locNbVis;
- fbounds.bottom = fLineHeight * locNbVis + 3;
- fbounds.right = rct.right - 18;
- cbounds.right = fbounds.right - 3;
- if (cbounds.right > fGWorld->portRect.right)
- {
- cbounds.right = fGWorld->portRect.right;
- fbounds.right = cbounds.right + 3;
- }
- ::CopyBits((BitMapPtr)(*(GetGWorldPixMap(fGWorld))), &(((GrafPtr)(facet->GetWindow(ev)->GetPlatformWindow(ev)))->portBits), &cbounds, &fbounds, srcCopy, nil);
- }
-
- void ListPart::NewSel(Environment* ev, ODFacet* facet, short whereto, short wherefrom, char tosel)
- {
- short i, j, k;
-
- if (whereto > fNbLines) return;
- if (fKind == kPassive) fsomSelf->SetSel(ev, facet, whereto);
- if (fKind == kMultiple)
- {
- if (whereto > wherefrom) {i=wherefrom; j=whereto;} else {i=whereto; j=wherefrom;}
- for(k=i; k<=j; k++)
- if (fMul[k-1] != tosel)
- {
- fMul[k-1] = tosel;
- if ((k >= fListIndex) && (k < fListIndex+fGWNbLines)) DrawCell(ev, facet, k);
- SetDirty(ev);
- }
- }
- }
-
- void ListPart::CloseCellOpened(Environment* ev)
- {
- ODSession* session = ODGetSession(ev, fSelf);
- session->GetDispatcher(ev)->UnregisterIdle(ev, fSelf, fOpenedFacet->GetFrame(ev));
- fsomSelf->CloseOpenedCell(ev, fOpenedFacet);
- DrawCell(ev, fOpenedFacet, fSel);
- CopyFromGWorld(ev, fOpenedFacet);
- {
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- ODFrameFacetIterator* facets = proxy->GetFrame(ev)->CreateFacetIterator(ev);
- for (ODFacet* fct = facets->First(ev);
- facets->IsNotComplete(ev);
- fct = facets->Next(ev) )
- {
- if (fct != fOpenedFacet)
- {
- CFocus lfoc(ev, fct);
- CopyFromGWorld(ev, fct);
- }
- }
- delete facets;
- }
- }
- fLineOpened = 0;
- fOpenedFacet = kODNULL;
- SetDirty(ev);
- }
-
- void ListPart::ScrollTo(Environment* ev, ODFacet* facet, short whereto)
- {
- short newListIndex;
- short x;
- Rect fromBounds, toBounds;
-
- if (!fGWorld) return;
-
- if (whereto > fNbLines) return;
- newListIndex = (whereto>(fNbLines-fGWNbLines+1))?(fNbLines-fGWNbLines+1):whereto;
- if ((newListIndex+fGWNbLines-1 < fListIndex) || (newListIndex > fListIndex+fGWNbLines-1))
- {
- fListIndex = newListIndex;
- DrawMultCell(ev, facet, newListIndex, newListIndex+fGWNbLines-1);
- }
- else
- {
- if (newListIndex < fListIndex)
- {
- x = fListIndex - newListIndex;
- fromBounds = toBounds = fGWorld->portRect;
- fromBounds.bottom = (fGWNbLines-x) * fLineHeight;
- toBounds.top = x * fLineHeight;
- ::CopyBits((BitMapPtr)(*(GetGWorldPixMap(fGWorld))), (BitMapPtr)(*(GetGWorldPixMap(fGWorld))), &fromBounds, &toBounds, srcCopy, nil);
- fListIndex = newListIndex;
- DrawMultCell(ev, facet, newListIndex, newListIndex+x-1);
- }
- if (newListIndex > fListIndex)
- {
- x = newListIndex - fListIndex;
- fromBounds = toBounds = fGWorld->portRect;
- fromBounds.top = x * fLineHeight;
- toBounds.bottom = (fGWNbLines-x) * fLineHeight;
- ::CopyBits((BitMapPtr)(*(GetGWorldPixMap(fGWorld))), (BitMapPtr)(*(GetGWorldPixMap(fGWorld))), &fromBounds, &toBounds, srcCopy, nil);
- fListIndex = newListIndex;
- DrawMultCell(ev, facet, newListIndex+fGWNbLines-x, newListIndex+fGWNbLines-1);
- }
- }
- CopyFromGWorld(ev, facet);
- SetDirty(ev);
- }
-
- short ListPart::FirstClick(Environment* ev, ODFacet* facet, ODEventData* event, short* where, char* val, Point macPoint)
- {
- short idx, i;
- char *ps;
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- ControlHandle aCtl = lfip->fListCtl;
- /*
- ODWindow* odwnd = facet->GetFrame(ev)->AcquireWindow(ev);
- ODPoint facetPoint;
- GetWindowPoint(odwnd, ev, event->where, &facetPoint);
- ODTransform* transform = facet->AcquireWindowContentTransform(ev, kODNULL);
- transform->InvertPoint(ev, &facetPoint);
- transform->Release(ev);
- odwnd->Release(ev);
- */
- CFocus foc(ev, facet);
- // Point macPoint = facetPoint.AsQDPoint();
- Rect rct = lfip->fUsedRect;
- idx = ((macPoint.v - rct.top - 3 - 1) / fLineHeight) + ::GetControlValue(aCtl);
-
- if (fKind == kActive) if (fLineOpened && (idx != fSel)) CloseCellOpened(ev);
-
- if (fKind != kActive)
- {
- fDoubleClickedLine = -1;
- if (idx == fLastClickedLine)
- if (event->when - fLastClickTime < ::GetDblTime()) fDoubleClickedLine = idx;
- fLastClickedLine = idx;
- fLastClickTime = event->when;
- if (fDoubleClickedLine != -1)
- {
- fsomSelf->GotDoubleClick(ev, facet, fDoubleClickedLine);
- return(false);
- }
- }
-
- if (ClickWithMod(ev, facet, event)) return(false);
- if (idx > fNbLines) return(false);
- if ((fKind == kActive) || (fKind == kPassive))
- if (idx != fSel)
- {
- fsomSelf->SetSel(ev, facet, idx);
- gTempoVal = 1;
- CopyFromGWorld(ev, facet);
- }
- if (fKind == kActive)
- {
- ODSession* session = ODGetSession(ev, fSelf);
- fLineOpened = 1;
- fOpenedFacet = facet;
- rct.top = rct.top + 3 + fLineHeight * (idx - ::GetControlValue(aCtl));
- rct.bottom = rct.top + fLineHeight;
- rct.right -= 18;
- session->GetDispatcher(ev)->RegisterIdle(ev, fSelf, facet->GetFrame(ev), 4);
- fsomSelf->ClickInActive(ev, facet, event, &rct);
- return(false);
- }
- if (fKind == kMultiple)
- {
- if ((event->modifiers & shiftKey) && (fSel != -1))
- {
- *val = fMul[fSel-1];
- ps = (idx > fSel)?(&fMul[fSel-1]):(&fMul[idx-1]);
- for (i=0; i<=mabs(fSel-idx); i++) *ps++ = *val;
- DrawMultCell(ev, facet, fListIndex, fListIndex+fGWNbLines-1);
- }
- else
- {
- *val = !fMul[idx-1];
- fMul[idx-1] = *val;
- DrawCell(ev, facet, idx);
- }
- gTempoVal = 1;
- CopyFromGWorld(ev, facet);
- fSel = idx;
- }
- *where = idx;
- return(true);
- }
-
- void ListPart::StillClick(Environment* ev, ODFacet* facet, short where, char val)
- {
- Point localPt;
- short idx, whereto, j;
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- ControlHandle aCtl = lfip->fListCtl;
- short locNbVis = lfip->fNbVis;
- short curCtlValue = ::GetControlValue(aCtl);
-
- CFocus foc(ev, facet);
- Rect rct = lfip->fUsedRect;
-
- GetMouse(&localPt);
- idx = ((localPt.v - rct.top - 3 - 1) / fLineHeight) + 1;
- if (localPt.v < rct.top + 3) idx -= 1;
- if ((idx >= 1) && (idx <= locNbVis))
- {
- whereto = idx + curCtlValue - 1;
- if (whereto > fNbLines) whereto = fNbLines;
- j = 0;
- if (fKind == kPassive) j = (whereto != fSel);
- if (fKind == kMultiple) j = (fMul[whereto-1] != val);
- if ((fKind != kActive) && (j != 0))
- {
- NewSel(ev, facet, whereto, where, val);
- CopyFromGWorld(ev, facet);
- gTempoVal = 1;
- }
- }
- else if (fKind != kActive)
- {
- short curCtlMax = ::GetControlMaximum(aCtl);
- j = (idx <= 0)?(idx+curCtlValue-1):(idx+curCtlValue-locNbVis);
- whereto = idx+curCtlValue-1;
- j = (j<1)?1:j;
- j = (j>curCtlMax)?curCtlMax:j;
- whereto = (whereto < 1)?1:whereto;
- whereto = (whereto > fNbLines)?fNbLines:whereto;
- NewSel(ev, facet, whereto, where, val);
- if (j != curCtlValue)
- {
- UtilSetControlValue(aCtl, j);
- ScrollTo(ev, facet, ::GetControlValue(aCtl));
- }
- else CopyFromGWorld(ev, facet);
- gTempoVal = 1;
- }
- if (fKind == kMultiple) fSel = whereto;
- }
-
- short ListPart::ClickWithMod(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- char *ps, val;
- short i;
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- ControlHandle aCtl = lfip->fListCtl;
-
- if (fKind == kMultiple)
- {
- ps = fMul;
- if (event->modifiers & optionKey)
- {
- val = (event->modifiers & shiftKey)?1:0;
- for (i=0; i<=fNbLines-1; i++) *ps++ = val;
- DrawMultCell(ev, facet, fListIndex, fListIndex+fGWNbLines-1);
- CopyFromGWorld(ev, facet);
- gTempoVal = 1;
- return(true);
- }
- if (event->modifiers & cmdKey)
- {
- i = 0;
- while (!(*ps++)) i++;
- i = (i >= fNbLines)?0:(i-1);
- UtilSetControlValue(aCtl, i+1);
- ScrollTo(ev, facet, ::GetControlValue(aCtl));
- gTempoVal = 1;
- return(true);
- }
- }
- if ((fKind == kPassive) || (fKind == kActive))
- if (event->modifiers & cmdKey)
- {
- if (fKind == kActive) if (fLineOpened) CloseCellOpened(ev);
- UtilSetControlValue(aCtl, fSel-1);
- ScrollTo(ev, facet, ::GetControlValue(aCtl));
- gTempoVal = 1;
- return(true);
- }
- return(false);
- }
-
- short ListPart::KeyInList(Environment* ev, char theChar)
- {
- short where, val, didGetKey = 1;
- CFocus lfoc(ev, fFocusedFacet);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)fFocusedFacet->GetPartInfo(ev);
- ControlHandle aCtl = lfip->fListCtl;
- short locNbVis = lfip->fNbVis;
- val = ::GetControlValue(aCtl);
- switch (theChar)
- {
- case 1: /* Home */
- where = 1;
- break;
- case 4: /* End */
- where = ::GetControlMaximum(aCtl);
- break;
- case 11: /* PageUp */
- where = val - locNbVis + 1;
- break;
- case 12: /* PageDown */
- where = val + locNbVis - 1;
- break;
- case 30: /* LineUp */
- where = val - 1;
- break;
- case 31: /* LineDown */
- where = val + 1;
- break;
- default:
- if (fWantKey) where = fsomSelf->KeyShortCut(ev, theChar); else didGetKey = 0;
- break;
- }
- if (didGetKey == 0) return(false);
-
- UtilSetControlValue(aCtl, where);
- where = ::GetControlValue(aCtl);
-
- if (val != where)
- {
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- ODFrameFacetIterator* facets = proxy->GetFrame(ev)->CreateFacetIterator(ev);
- for (ODFacet* fct = facets->First(ev);
- facets->IsNotComplete(ev);
- fct = facets->Next(ev) )
- {
- CFocus lfoc(ev, fct);
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)fct->GetPartInfo(ev);
- UtilSetControlValue(lfip->fListCtl, where);
- ScrollTo(ev, fct, where);
- }
- delete facets;
- }
- }
- return(true);
- }
-
- #define SUSV(prop,kind,len,addr) { \
- ODSUForceFocus(ev, storageUnit, (prop), (kind)); \
- ODULong oldSize = storageUnit->GetSize(ev); \
- StorageUnitSetValue(storageUnit, ev, (len), (addr)); \
- ODULong newSize = storageUnit->GetOffset(ev); \
- if (newSize < oldSize) storageUnit->DeleteValue(ev, oldSize - newSize); }
-
- void ListPart::ExternalizeListParams(Environment* ev, ODStorageUnit* storageUnit)
- {
- WeBeHere("\pListPart::ExternalizeListParams");
-
- SUSV(kODPropListListIndex, kListShort, sizeof(short), &fListIndex)
- SUSV(kODPropListNbLines, kListShort, sizeof(short), &fNbLines)
- SUSV(kODPropListLineHeight, kListShort, sizeof(short), &fLineHeight)
- SUSV(kODPropListLineWidth, kListShort, sizeof(short), &fLineWidth)
- SUSV(kODPropListLineDepth, kListShort, sizeof(short), &fLineDepth)
- SUSV(kODPropListAutoThumb, kListShort, sizeof(short), &fAutoThumb)
- SUSV(kODPropListWantKey, kListShort, sizeof(short), &fWantKey)
- SUSV(kODPropListKind, kListShort, sizeof(short), &fKind)
- SUSV(kODPropListSel, kListShort, sizeof(short), &fSel)
- if (fKind != kMultiple)
- {
- char dummy = 0;
- SUSV(kODPropListMul, kListChars, 1, &dummy)
- }
- else
- SUSV(kODPropListMul, kListChars, fNbLines, fMul)
-
- fsomSelf->ExternalizeListData(ev, storageUnit);
- }
-
- #define SUGV(prop,kind,len,addr,msg) { \
- if (ODSUExistsThenFocus(ev, storageUnit, (prop), (kind))) \
- if ((theSize = storageUnit->GetSize(ev)) != len) DebugStr((msg)); \
- else StorageUnitGetValue(storageUnit, ev, (len), (addr)); }
-
- void ListPart::InternalizeListParams(Environment* ev, ODStorageUnit* storageUnit)
- {
- WeBeHere("\pListPart::InternalizeListParams");
- long theSize;
-
- SUGV(kODPropListListIndex, kListShort, sizeof(short), &fListIndex, "\pStorage size for ListIndex is wrong !")
- SUGV(kODPropListNbLines, kListShort, sizeof(short), &fNbLines, "\pStorage size for NbLines is wrong !")
- SUGV(kODPropListLineHeight, kListShort, sizeof(short), &fLineHeight,"\pStorage size for LineHeight is wrong !")
- SUGV(kODPropListLineWidth, kListShort, sizeof(short), &fLineWidth, "\pStorage size for LineWidth is wrong !")
- SUGV(kODPropListLineDepth, kListShort, sizeof(short), &fLineDepth, "\pStorage size for LineDepth is wrong !")
- SUGV(kODPropListAutoThumb, kListShort, sizeof(short), &fAutoThumb, "\pStorage size for AutoThumb is wrong !")
- SUGV(kODPropListWantKey, kListShort, sizeof(short), &fWantKey, "\pStorage size for WantKey is wrong !")
- SUGV(kODPropListKind, kListShort, sizeof(short), &fKind, "\pStorage size for Kind is wrong !")
- SUGV(kODPropListSel, kListShort, sizeof(short), &fSel, "\pStorage size for Sel is wrong !")
- if (fKind == kMultiple)
- if (ODSUExistsThenFocus(ev, storageUnit, kODPropListMul, kListChars))
- {
- if ((theSize = storageUnit->GetSize(ev)) != fNbLines) DebugStr("\pStorage size for Mul is wrong !");
- else
- {
- fMul = NewPtr(theSize);
- OSErr err = MemError(); if (!fMul) err = err?err:memFullErr;
- if (err) DebugStr("\punable to alloc fMul in ListPart::InternalizeListParams");
- StorageUnitGetValue(storageUnit, ev, theSize, fMul);
- }
- }
- else fMul = kODNULL;
-
- fsomSelf->InternalizeListData(ev, storageUnit);
- }
-
- #define APAV(prop,kind) { \
- if ( !storageUnit->Exists(ev, (prop), kODNULL, 0) ) \
- storageUnit->AddProperty(ev, (prop)); \
- if ( !storageUnit->Exists(ev, (prop), (kind), 0) ) \
- { \
- storageUnit->Focus(ev, (prop), kODPosUndefined, kODNULL, 0, kODPosAll); \
- storageUnit->AddValue(ev, (kind)); \
- } }
-
- void ListPart::SetUpListParams(Environment* ev, ODStorageUnit* storageUnit)
- {
- WeBeHere("\pListPart::SetUpListParams");
-
- APAV(kODPropListListIndex, kListShort)
- APAV(kODPropListNbLines, kListShort)
- APAV(kODPropListLineHeight, kListShort)
- APAV(kODPropListLineWidth, kListShort)
- APAV(kODPropListLineDepth, kListShort)
- APAV(kODPropListAutoThumb, kListShort)
- APAV(kODPropListWantKey, kListShort)
- APAV(kODPropListKind, kListShort)
- APAV(kODPropListSel, kListShort)
- APAV(kODPropListMul, kListChars)
-
- fsomSelf->SetUpListData(ev, storageUnit);
- }
-
- void ListPart::ShowMe(Environment* ev, ODFacet* facet, short theLine)
- {
- ListFacetInfoPtr lfip = (ListFacetInfoPtr)facet->GetPartInfo(ev);
- short locNbVis = lfip->fNbVis;
- ControlHandle aCtl = lfip->fListCtl;
- short curCtlValue = ::GetControlValue(aCtl);
- if ((theLine >= curCtlValue) && (theLine <= curCtlValue+locNbVis-1)) return;
- UtilSetControlValue(aCtl, theLine-1);
- ScrollTo(ev, facet, ::GetControlValue(aCtl));
- gTempoVal = 1;
- }
-
- short ListPart::GetNbLines(Environment* ev)
- {
- return fNbLines;
- }
-
- short ListPart::GetSel(Environment* ev)
- {
- return fSel;
- }
-
- void ListPart::SetNbLines(Environment* ev, short newNbLines)
- {
- /*
- for (FacetLink *fl = fFacets.First(); fl->Facet(); fl=fl->Next())
- {
- CFocus lfoc(ev, fl->Facet());
- ControlHandle aCtl = fl->ListCtl();
- short locNbVis = fl->GetNbVis();
- short theMax = newNbLines - locNbVis + 1;
- if (theMax < 1) theMax = 1;
- ::SetControlMaximum(aCtl, theMax);
- if (fKind == kMultiple)
- {
- char* newfmul = (char *)NewPtrClear(newNbLines);
- OSErr err = MemError(); if (!newfmul) err = err?err:memFullErr;
- if (err) DebugStr("\punable to realloc fMul in ListPart::ModifyNbLines");
- BlockMove((Ptr)fMul, (Ptr)newfmul, (newNbLines > fNbLines)?fNbLines:newNbLines);
- DisposePtr((Ptr)fMul);
- fMul = newfmul;
- }
- if (fListIndex+fGWNbLines-1 > newNbLines)
- {
- fListIndex = newNbLines-fGWNbLines+1;
- DrawMultCell(ev, fl->Facet(), fListIndex, fListIndex+fGWNbLines-1);
- CopyFromGWorld(ev, fl->Facet());
- }
- }
- fNbLines = newNbLines;
- */
- }
-
- void ListPart::SetSel(Environment* ev, ODFacet* facet, short theLine)
- {
- short oldfsel;
-
- if (theLine != fSel)
- {
- oldfsel = fSel;
- fSel = theLine;
- if ((oldfsel >= fListIndex) && (oldfsel < fListIndex+fGWNbLines)) DrawCell(ev, facet, oldfsel);
- if ((fSel >= fListIndex) && (fSel < fListIndex+fGWNbLines)) DrawCell(ev, facet, fSel);
- SetDirty(ev);
- }
- }
-
- void ListPart::SetUpGraphics(Environment* ev, GWorldPtr theGWorld)
- {
- }
-
- void ListPart::FillCell(Environment* ev, short theLine, Rect* theRect)
- {
- ::MoveTo(theRect->left+1, theRect->bottom-3);
- switch(theLine)
- {
- case 1:
- ::DrawString("\pVirtual Part only !");
- break;
- case 2:
- ::DrawString("\pInherit from it to use it");
- break;
- }
- }
-
- void ListPart::FillHilCell(Environment* ev, short theLine, Rect* theRect)
- {
- fsomSelf->FillCell(ev, theLine, theRect);
- ::InvertRect(theRect);
- }
-
- void ListPart::ClickInActive(Environment* ev, ODFacet* facet, ODEventData* event, Rect* theRect)
- {
- }
-
- void ListPart::CloseOpenedCell(Environment* ev, ODFacet* facet)
- {
- }
-
- void ListPart::IdleOpened(Environment* ev, ODFacet* facet)
- {
- }
-
- short ListPart::KeyInActive(Environment* ev, ODFacet* facet, ODEventData* event)
- {
- return(false);
- }
-
- short ListPart::KeyShortCut(Environment* ev, char theChar)
- {
- return((theChar-' ')*10); // just a test
- }
-
- void ListPart::GotDoubleClick(Environment* ev, ODFacet* facet, short theLine)
- {
- }
-
- void ListPart::ExternalizeListData(Environment* ev, ODStorageUnit* storageUnit)
- {
- }
-
- void ListPart::InternalizeListData(Environment* ev, ODStorageUnit* storageUnit)
- {
- }
-
- void ListPart::SetUpListData(Environment* ev, ODStorageUnit* storageUnit)
- {
- }
-
- void ListPart::InitializeListData(Environment* ev,
- short* pNbLines,short* pLineHeight,short* pLineWidth,short* pLineDepth,short* pKind,
- short* pAutoThumb,short* pWantKey,short* pListIndex,short* pSel,char** pMul)
- {
- WeBeHere("\pListPart::InitializeListData");
- *pNbLines = 2;
- *pLineHeight = 18;
- *pLineWidth = 400;
- *pLineDepth = 1;
- *pKind = kNull;
- *pAutoThumb = 0;
- *pWantKey = 0;
- *pListIndex = 1;
- *pMul = 0L;
- }
-
- ODISOStr ListPart::GetTheRealPartKind(Environment* ev)
- { return kListPartKind; }
-
- ODSLong ListPart::OverrideBeginUsingLibraryResources(Environment* ev)
- { return BeginUsingLibraryResources(); }
-
- void ListPart::OverrideEndUsingLibraryResources(Environment* ev, ODSLong ref)
- { EndUsingLibraryResources(ref); }
-